/**
 * 登录
 */

export const SIGNIN = "SIGNIN"
export const SIGNIN_SUCCESS = "SIGNIN_SUCCESS"
export const SIGNIN_FAIL = "SIGNIN_FAIL"

export interface signInPayload {
    email:string
    password:string
}

export interface signInAction {
    type:typeof SIGNIN
    payload: signInPayload
}

export interface signInSuccessAction {
    type:typeof SIGNIN_SUCCESS
}

export interface signInFailAction {
    type:typeof SIGNIN_FAIL
    message:string
}

export const signIn = (payload:signInPayload):signInAction => ({
    type:SIGNIN,
    payload
})

export const signInSuccess = ():signInSuccessAction => ({
    type:SIGNIN_SUCCESS
})

export const signInFail = (message:string):signInFailAction => ({
    type:SIGNIN_FAIL,
    message
})
/**
 * 注册
 */

export const SIGNUP = "SIGNUP"
export const SIGNUP_SUCCESS = "SIGNUP_SUCCESS"
export const SIGNUP_FAIL = "SIGNUP_FAIL"

export interface signUpPayload {
    email: string
    name: string
    password: string
}

export interface signUpAction {
    type:typeof SIGNUP
    payload: signUpPayload
}

export interface signUpSuccessAction {
    type:typeof SIGNUP_SUCCESS
}

export interface signUpFailAction {
    type:typeof SIGNUP_FAIL
    message:string
}

export const signUp = (payload:signUpPayload):signUpAction => ({
    type:SIGNUP,
    payload
})

export const signUpSuccess = ():signUpSuccessAction => ({
    type:SIGNUP_SUCCESS
})

export const signUpFail = (message:string):signUpFailAction => ({
    type:SIGNUP_FAIL,
    message
})
export type AuthUnionType =
  | signInAction
  | signInSuccessAction
  | signInFailAction
  | signUpAction
  | signUpSuccessAction
  | signUpFailAction